/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pingouin;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Hippolyte
 */
public class TServeurDebut extends Thread {

    public final String awake = new String();

    public static final int PORT = 8057;
    
    public main m;

    public TServeurDebut(main m) {
        this.m = m;
    }
    
    
    
    @Override
    public void run() {

        int i = 0;

        ArrayList<InetAddress> adressesConnues = new ArrayList<>();
        
        InetAddress temp;

        for (Joueur j : Partie.ressources.joueurs) {
            if (!j.surCetOrdi) {
                i++;
                System.out.println("attente joueur " + i);

                try {
                    ServerSocket s = new ServerSocket(PORT);
                    Socket soc = s.accept();
                    
                    System.out.println("recu");

                    
                    temp = soc.getInetAddress();
                    
                    if(!adressesConnues.contains(temp)){
                        j.address = temp;
                        adressesConnues.add(temp);
                        System.out.println("joueur " + i + " a l'adresse " + temp.toString());
                    }
                    
                    soc.close();
                } catch (IOException ex) {
                    Logger.getLogger(TServeurCoord.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        }
        
        m.debutPartie();
        
    }
}
